package main

import (
	"fmt"
	"time"
	"encoding/json"
)

type DepartmentGo struct{}

type Department struct {
	Key            string `json:"key,omitempty"`
	DepartmentName string `json:"DepartmentName,omitempty"`
	CreateTime     string `json:"CreateTime,omitempty"`
	UpdateTime     string `json:"UpdateTime,omitempty"`
}



type DE struct {
	Key        string `json:"key,omitempty"`
	DEDKey     string `json:"DEDKey,omitempty"`
	DEEKey     string `json:"DEEKey,omitempty"`
	CreateTime string `json:"CreateTime,omitempty"`
	Desc       string `json:"Desc,omitempty"`
}

type Mango struct {
	Selector Department `json:"selector"`
}
type MangoCount struct {
	SelectorCount Count      `json:"selector"`
}

type Count struct {
	Key    string `json:"key,omitempty"`
	CDKey  string `json:"CDKey,omitempty"`
	Type   string `json:"Type,omitempty"` //统计类型 year、month、day、hour、minute
	Year   string `json:"Year,omitempty"` //
	Month  string `json:"Month,omitempty"`
	Day    string `json:"Day,omitempty"`
	Hour   string `json:"Hour,omitempty"`
	Minute string `json:"Minute,omitempty"`
	Count  int    `json:"Count,omitempty"`
}
func main() {
	key := "1111"
	timeNow := time.Now().Format("2006-01-02 15:04:05")
	fmt.Println(timeNow)
	year := string([]byte(timeNow)[:4])
	month := string([]byte(timeNow)[5:7])
	day := string([]byte(timeNow)[8:10])
	hour := string([]byte(timeNow)[11:13])
	minute := string([]byte(timeNow)[14:16])

	yearString := fmt.Sprintf(`{"selector":{"CDKey":"%s","Type":"year","Year":"%s"}}`, key, year)
	monthString := fmt.Sprintf(`{"selector":{"CDKey":"%s","Type":"month","Year":"%s","Month":"%s"}}`, key, year, month)
	dayString := fmt.Sprintf(`{"selector":{"CDKey":"%s","Type":"day","Year":"%s","Month":"%s","Day":"%s"}}`, key, year, month, day)
	hourString := fmt.Sprintf(`{"selector":{"CDKey":"%s","Type":"hour","Year":"%s","Month":"%s","Day":"%s","Hour":"%s"}}`, key, year, month, day, hour)
	minuteString := fmt.Sprintf(`{"selector":{"CDKey":"%s","Type":"minute","Year":"%s","Month":"%s","Day":"%s","Hour":"%s","Minute":"%s"}}`, key, year, month, day, hour, minute)
	queryString := append([]string{}, yearString, monthString, dayString, hourString, minuteString)
	fmt.Println(queryString)
	for _, v := range queryString {

		//插入
		var o1 MangoCount
		fmt.Println(v)
		json.Unmarshal([]byte(v), &o1)
		o := o1.SelectorCount
		o.Count = 1
		dbData, _ := json.Marshal(o)
		fmt.Println(string(dbData))

	}
}
